package view;

import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;

import controller.ACSystem;
import model.Bid;
import model.Bidder;
import javax.swing.border.LineBorder;

/**
 * The BidderPane class
 * 
 * @author Bob Landowski
 */
@SuppressWarnings("serial")
public class BidderPane extends JPanel {

	/** The Bidder */
	@SuppressWarnings("unused")
	private Bidder my_bidder;

	/** The first name */
	private String my_first_name;

	/** The last name */
	private String my_last_name;

	/** Label for the first_Name_Label field. */
	private JLabel first_Name_Label;

	/** Label for the last_Name_Label field. */
	private JLabel last_Name_Label;

	/** Label for the address_1_Label field. */
	private JLabel address_1_Label;

	/** Label for the address_2_Label field. */
	private JLabel address_2_Label;

	/** Label for the city_Label field. */
	private JLabel city_Label;

	/** Label for the state_Label field. */
	private JLabel state_Label;

	/** Label for the zip_Label field. */
	private JLabel zip_Label;

	/** Label for the email_Label field. */
	private JLabel email_Label;

	/** Label for the phone_Label field. */
	private JLabel phone_Label;

	/** The list of bids */
	@SuppressWarnings("unused")
	private ArrayList<Bid> my_bids;

	/** The ACcontroller */
	@SuppressWarnings("unused")
	private ACSystem my_ACcontroller;

	/**
	 * Create the panel.
	 * 
	 * @author Bob Landowski
	 * @author Eric Struck
	 */
	public BidderPane(final ACSystem the_ACcontroller) {
		setBorder(new LineBorder(new Color(0, 0, 0), 5));
		my_ACcontroller = the_ACcontroller;
		setPreferredSize(new Dimension(500, 500));
		setLayout(null);

		JLabel firstnameLabel = new JLabel("First Name:");
		firstnameLabel.setBounds(15, 46, 85, 20);
		add(firstnameLabel);

		JLabel lastNameLabel = new JLabel("Last Name:");
		lastNameLabel.setBounds(15, 76, 100, 20);
		add(lastNameLabel);

		JLabel address1_label = new JLabel("Address:");
		address1_label.setBounds(15, 106, 69, 20);
		add(address1_label);

		JLabel address_label2 = new JLabel("");
		address_label2.setBounds(15, 136, 69, 20);
		add(address_label2);

		JLabel cityLabel = new JLabel("City:");
		cityLabel.setBounds(15, 166, 47, 20);
		add(cityLabel);

		JLabel stateLabel = new JLabel("State:");
		stateLabel.setBounds(240, 166, 47, 20);
		add(stateLabel);

		JLabel zipCodeLabel = new JLabel("Zip Code:");
		zipCodeLabel.setBounds(15, 196, 69, 20);
		add(zipCodeLabel);

		JLabel phone_label = new JLabel("Phone:");
		phone_label.setBounds(240, 226, 69, 20);
		add(phone_label);

		JLabel email_label = new JLabel("Email:");
		email_label.setBounds(15, 226, 69, 20);
		add(email_label);

		JLabel AuctionCentralBidderLabel = new JLabel(
				"Auction Central Bidder Screen");
		AuctionCentralBidderLabel.setBounds(130, 16, 200, 20);
		add(AuctionCentralBidderLabel);

		// JButton bidHistoryButton = new JButton("Bid History");
		// bidHistoryButton.addActionListener(new ActionListener() {
		//
		//
		// private Component my_mainframe;
		//
		// public void actionPerformed(ActionEvent e) {
		// my_bidder = (Bidder)my_ACcontroller.getCurrentUser();
		// if(!my_bidder.findBids().equals(null)){
		// Object[] possibilities = new Object[my_bidder.findBids().size()];
		//
		// for (int i = 0; i < my_bidder.findBids().size(); i++) {
		// possibilities[i] = my_bidder.findBids().get(i).toString();
		// }
		//
		// String s = (String) JOptionPane.showInputDialog(my_mainframe,
		// null, "Bid History",
		// JOptionPane.PLAIN_MESSAGE, null, possibilities, null);
		//
		// String[] words = s.split("~");
		// int x = 0;
		// if (my_ACcontroller.isNumeric(words[0])) {
		// x = (int) Double.parseDouble(words[0]);
		// }
		// Item item = null;
		// boolean found = false;
		// for (int i = 0; i < my_ACcontroller.getMy_auctions().size(); i++){
		// for(int j = 0; j <
		// my_ACcontroller.getMy_auctions().get(i).getItemList().size(); j++) {
		// item = my_ACcontroller.getMy_auctions().get(i).getItemList().get(j);
		// if (item.getMyItemNumber() == x) {
		// // item found:
		// found = true;
		// break;
		// }
		// }
		// if (found) break;
		// } // end of for-loop
		//
		// my_ACcontroller.setWestPanel(WestPanelEnum.ITEM);
		// my_ACcontroller.getMainFrame().westPanelState(item);
		//
		// }else{
		//
		// JOptionPane.showMessageDialog(my_mainframe,
		// "There is no Bid history",
		// null,
		// JOptionPane.ERROR_MESSAGE);
		// }
		// }
		// });
		//
		// bidHistoryButton.setBounds(165, 320, 148, 29);
		// add(bidHistoryButton);

		first_Name_Label = new JLabel(my_first_name);
		first_Name_Label.setBounds(115, 46, 206, 20);
		add(first_Name_Label);

		last_Name_Label = new JLabel(my_last_name);
		last_Name_Label.setBounds(115, 76, 206, 20);
		add(last_Name_Label);

		address_1_Label = new JLabel("");
		address_1_Label.setBounds(115, 106, 206, 20);
		add(address_1_Label);

		address_2_Label = new JLabel("");
		address_2_Label.setBounds(94, 136, 206, 20);
		add(address_2_Label);

		city_Label = new JLabel("");
		city_Label.setBounds(115, 166, 104, 20);
		add(city_Label);

		state_Label = new JLabel("");
		state_Label.setBounds(286, 166, 104, 20);
		add(state_Label);

		zip_Label = new JLabel("");
		zip_Label.setBounds(115, 196, 104, 20);
		add(zip_Label);

		email_Label = new JLabel("");
		email_Label.setBounds(104, 226, 115, 20);
		add(email_Label);

		phone_Label = new JLabel("");
		phone_Label.setBounds(286, 226, 115, 20);
		add(phone_Label);
	}

	/**
	 * The getObjectData method
	 */
	public void getObjectData(Object the_object) {
		Bidder my_bidder = (Bidder) the_object;

		my_bids = my_bidder.findBids();

		first_Name_Label.setText(my_bidder.get_first_name());
		last_Name_Label.setText(my_bidder.get_last_name());
		address_1_Label.setText(my_bidder.getMy_address().getMy_address1()
				+ " " + my_bidder.getMy_address().getMy_apt_num());
		address_2_Label.setText(my_bidder.getMy_address().getMy_address2());
		city_Label.setText(my_bidder.getMy_address().getMy_city());
		state_Label.setText(my_bidder.getMy_address().getMy_state());
		zip_Label.setText(my_bidder.getMy_address().getMy_zip());
		email_Label.setText(my_bidder.getMy_email());
		phone_Label.setText(my_bidder.getMy_phone());

	}
}
